<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: TagController.php 197 2011-02-18 12:45:33Z beimuaihui $
 */

require_once 'Zend/Controller/Action.php';
require_once 'Tag.php';
class Microblog_TagController extends Baogg_Controller_Action {
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
		//var_dump($this->getFrontController()->getBaseUrl());
		

		$db = Baogg_Db::getDb ('master');
		
		$stmt = $db->query ( "select * from {BAOGG_MDB_PREFIX}user;" );
		//var_dump($stmt->fetchAll());
	

	//$stmt = $db->prepare("INSERT INTO server (key, value) VALUES (:key, :value)");
	

	//$stmt->bindParam('key', $key);
	//$stmt->bindParam('value', $value);
	

	//foreach ($_SERVER as $key => $value) {
	//	$stmt->execute();
	//}
	}
	public function viewmyAction() {
		$creator = ( int ) $_SESSION ['s_user_id'];
		$where [] = "a.editor={$creator}";
		$where [] = "a.state=1";
		$tag = new Tag ( );
		$rs = $tag->getList ( $where );
		foreach ( ( array ) $rs as $k => $v ) {
			$rs [$k] ['edit'] = "";
		}
		$this->view->aTag=$rs;
	}
	public function listAction() {
	
	}
	public function rightsAction() {
	
	}
	public function bodyAction() {
	
	}
	public function addAction() {
		//var_dump($_SERVER['REQUEST_METHOD']);exit;
		if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
		}
		$form ['myForm'] = array ('action'=>BAOGG_BASE_URL."blog/tag/addsave/");
		$form ['myfld'] = array ('legend' => Translate::$add . " " . Translate::$tag, 'pid' => 'myForm' );
		$form ['tag_name'] = array ('class' => '', 'pid' => 'myfld' );
		$form ['description'] = array ('class' => '', 'pid' => 'myfld' );
		$form ['state'] = array ('class' => '', 'pid' => 'myfld', 'tag' => 'radio', 'data' => Translate::$aState );
		$form ['submit'] = array ('label' => false, 'type' => 'submit', 'pid' => 'myfld' );
		$form ['reset'] = array ('label' => false, 'type' => 'reset', 'plugin' => 'submit:3' );
		
		Zend_Loader::loadClass ( "Baogg_View_Form" );
		$form = new Baogg_View_Form ( $form );
		$this->view->form = $form;
	}
	public function addsaveAction() {
		$params=Baogg_Controller::getUrlParams();
		$params['editor']= ( int ) $_SESSION ['s_user_id'];
		//echo "<pre>";print_r($params);exit;
		Zend_Loader::loadClass("Tag");
		$tag=new Tag();
		$is_exist=$tag->getListByName($params['tag_name']);
		if(!$is_exist){
			$flag=$tag->add($params);
		}else{
			$flag=-1;
		}
		$this->view->flag=$flag;		
		//$this->_helper->viewRenderer->setNoRender ();
	}
}
